const express =require('express');
//1. 安装 cookie-parser npm i cookie-parser
//2. 引入 cookieParser 包
const cookieParser = require('cookie-parser');

const app = express();

//3. 设置 cookieParser 中间件
app.use(cookieParser());

//设置cookie
app.get('/set-cookie', (req, res) => {
  //不带时效性:关闭浏览器cookie就失效
  res.cookie('username','linxiao');
  //带时效性,单位是毫秒, 60×1000 是一分钟
  res.cookie('email','2487422771@qq.com',{maxAge:5*60*1000});
  //响应
  res.send('Cookie的设置');
});

// 读取cookie
app.get('/get-cookie',(req,res) => {
  //读取cookie
  console.log(req.cookies);
  res.send('Cookie的读取');
})

// 删除cookie
app.get('/delete-cookie',(req,res) => {
  //删除
  res.clearCookie('username');
  res.send('Cookie的清除');
})




app.listen(3000, () => {
  console.log('服务已经启动....');
});




















